/*
 * @Author: 陆成杰
 * @Date: 2022-06-23 11:23:06
 * @LastEditTime: 2022-07-02 13:58:20
 * @LastEditors: 陆成杰
 * @FilePath: /boe/src/axios/request.ts
 * Copyright (c) ${now_year} by zucc-陆成杰, All Rights Reserved. 
 */
import axios, { AxiosRequestConfig } from "axios"

export function request(config:AxiosRequestConfig) {
    const instance = axios.create({
        baseURL: 'http://localhost:3000/api',
        timeout: 5000
    })

    instance.interceptors.request.use(config => {
      console.log(config);
      config.headers.Authorization = window.localStorage.getItem('token')
      return config//一定要返回
    }, err => {
        console.log(err);
    })

    instance.interceptors.response.use(res => {
        return res.data
    }, err => {
        console.log(err);
    })

    return instance(config)
}